package com.kinoshita.common.exception;

import com.kinoshita.common.logger.LoggerUtil;
import com.kinoshita.common.result.WebResultDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {

    private static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @Autowired
    private LoggerUtil loggerUtil;

    @ExceptionHandler(SystemException.class)
    @ResponseBody
    public WebResultDO exceptionHandler(SystemException ex) {
        loggerUtil.setInfo("SystemExcepiton", ex.getStatusCode(), "", "");
        logger.error(loggerUtil.toString());
        return new WebResultDO(ex.getStatusCode().getCode(), ex.getStatusCode().getMsg());
    }

}
